﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;

namespace Site.Components
{
    public static class CommonExtensions
    {
        public static void GenerateYear(this ListControl lc, object selectedValue = null)
        {
            lc.Items.Clear();
            for (int i = 2011; i <= 2020; i++)
            {
                ListItem item = new ListItem(i.ToString() + "年", i.ToString());
                if (selectedValue != null)
                {
                    if (item.Value == selectedValue.ToString())
                    {
                        item.Selected = true;
                    }
                }
                lc.Items.Add(item);
            }
        }

        public static void GenerateMonth(this ListControl lc, object selectedValue = null)
        {
            lc.Items.Clear();
            for (int i = 1; i <= 12; i++)
            {
                ListItem item = new ListItem(i.ToString() + "月", i.ToString());
                if (selectedValue != null)
                {
                    if (item.Value == selectedValue.ToString())
                    {
                        item.Selected = true;
                    }
                }
                lc.Items.Add(item);
            }
        }

        public static void GenerateDay(this ListControl lc, object selectedValue = null)
        {
            lc.Items.Clear();
            for (int i = 1; i <= 31; i++)
            {
                ListItem item = new ListItem(i.ToString() + "日", i.ToString());
                if (selectedValue != null)
                {
                    if (item.Value == selectedValue.ToString())
                    {
                        item.Selected = true;
                    }
                }
                lc.Items.Add(item);
            }
        }

        public static DateTime AsDateTime(this string str)
        {
            return DateTime.Parse(str);
        }


       
    }
}